package org.yejiali.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.yejiali.common.response.ResponseResult;
import org.yejiali.service.ArticleService;

/**
 * @Author:yejiali
 * @Date:2025/2/14-02-14-16:43
 * @Decsription:org.yejiali.controller
 * @Version:1.0
 */
@Api(tags = "文章管理")
@RestController
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @ApiOperation(value = "获取数据")
    @GetMapping("/hotArticleList")
    public ResponseResult hotArticleList(){
        //查询热门文章 封装成ResponseResult返回
        ResponseResult result=articleService.hotArticleList();
        return result;
    }
    @GetMapping("/articleList")
    public ResponseResult articleList(@RequestParam(name = "pageNum") Integer pageNum,
                                      @RequestParam(name="pageSize") Integer pageSize,
                                      @RequestParam(name="categoryId") Long categoryId) {
        return articleService.articleList(pageNum,pageSize,categoryId);

    }
    @GetMapping("/{id}")
    public ResponseResult getArticleDetail(@PathVariable("id") Long id){

        return articleService.getArticleDetail(id);
    }

    @PutMapping("/updateViewCount/{id}")
    public ResponseResult updateViewCount(@PathVariable("id") Long id){
        return articleService.updateViewCount(id);
    }
}
